<template>
  <div class="dark:bg-zinc-800 bg-white sticky top-0 left-0 w-full z-10">
    <ul
      class="w-[800px] relative flex flex-wrap justify-center overflow-x-auto px-[10px] py-1 text-xs text-zinc-900 duration-300 overflow-hidden mx-auto"
      :class="isOpen ? 'h-[206px]' : 'h-[56px]'"
    >
      <!-- 展示箭头 -->
      <div
        @click="onClickIsOpen"
        class="dark:hover:bg-zinc-900 absolute right-1 bottom-1 z-20 p-1 rounded cursor-pointer duration-200 hover:bg-zinc-200"
      >
        <m-svg-icon
          class="w-1 h-1"
          :name="isOpen ? 'fold' : 'unfold'"
          fillClass="fill-zinc-900 dark:fill-zinc-300"
        />
      </div>
      <li
        v-for="(item, index) in $store.getters.categoryList"
        :key="item.id"
        @click="onClickItem(item)"
        class="dark:text-zinc-500 dark:hover:bg-zinc-900 dark:hover:text-zinc-300 px-1.5 py-0 z-10 duration-200 text-zinc-900 text-base font-bold h-4 leading-4 cursor-pointer hover:bg-zinc-200 rounded mr-1 mb-1"
        :class="{
          'bg-zinc-200 dark:text-zinc-300 dark:bg-zinc-90':
            $store.getters.currentCategoryIndex == index
        }"
      >
        {{ item.name }}
      </li>
    </ul>
  </div>
</template>

<script setup>
import { ref, reactive, toRefs, onMounted } from 'vue'
import { useStore } from 'vuex'

const store = useStore()

// 设置状态
const isOpen = ref(false)

const onClickIsOpen = () => {
  isOpen.value = !isOpen.value
}

// 设置当前点击高亮效果
// const currentIndex = ref(0)

const onClickItem = (item) => {
  // currentIndex.value = index
  store.commit('app/changeCurrentCategory', item)
}
</script>
<style scoped lang="scss"></style>
